{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "# 1、create  list列表\n",
    "# faceListId\n",
    "faceListId = \"renlian\" # 学生填写设置人脸列表ID\n",
    "create_facelists_url = \"https://renlian01.cognitiveservices.azure.com/face/v1.0/facelists/{}\".format(faceListId) # 学生填写 ☆ 注意此条url修改\n",
    "subscription_key = \"5b687b7615fa42e091a14868f10e1eb3\"\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "    \"name\": \"ggxx\",\n",
    "    \"userData\": \"gt\",\n",
    "    \"recognitionModel\": \"recognition_03\",\n",
    "    \n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url,headers=headers,json=data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [],\n",
       " 'faceListId': 'renlian',\n",
       " 'name': 'ggxx',\n",
       " 'userData': 'gt'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查你的facelist的信息\n",
    "get_facelist_url = \"https://renlian01.cognitiveservices.azure.com/face/v1.0/facelists/{}\".format(faceListId) # 学生填写\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url = \"https://renlian01.cognitiveservices.azure.com/face/v1.0/facelists/gt_list/persistedfaces\"\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"https://gitee.com/forevercan/resume/raw/master/assets/images/gtboy.jpg\"\n",
    "\n",
    "params_add_face={\n",
    "    \"userData\":\"gtboy\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "r_add_face.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [],\n",
       " 'faceListId': 'renlian',\n",
       " 'name': 'ggxx',\n",
       " 'userData': 'gt'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查你的facelist的信息\n",
    "get_facelist_url = \"https://renlian01.cognitiveservices.azure.com/face/v1.0/facelists/{}\".format(faceListId) \n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片/函数——可以重复使用相同的功能\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://renlian01.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://gitee.com/forevercan/resume/raw/master/assets/images/gtgirl.jpg\",\"gtgirl\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\",\"丘天惠\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\",\"林嘉茵\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\",\"汤玲萍\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\",\"曾雯燕\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\",\"谢依希\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/YuecongYang.png\",\"杨悦聪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg\",\"周雨\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg\",\"刘瑜鹏\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg\",\"陈嘉仪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/kg2000.jpg\",\"徐旖芊\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg\",\"刘心如\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuyu19.png\",\"刘宇\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '44ee1fd2-b3fe-459d-aba4-2ded992362fd',\n",
       "   'userData': 'gtgirl'},\n",
       "  {'persistedFaceId': '204dec44-248b-4ee6-b603-1c4fd04201df',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '55b7eb28-ead5-4d54-841a-8cff3d6c419d',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '89884e78-dcfa-4bb4-a7c4-bfa5941f260c',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '11c143b2-dda4-4d8e-a86f-ec4a8a71467c',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '4f68c1e2-04c1-4533-9fce-1f0e11a27d1e',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '2e83d372-3750-4fd3-8500-6214c7be002c',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '9d6c53f2-952f-4950-a822-795e055c70fc',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': 'b2d7b42c-9a5f-4668-99a0-2ef5d3f39f01',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '71476985-0011-4b1b-811a-1e289eee7502',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '3a3e1b73-de5e-42b1-b27c-ae820b987b55',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'ec681b46-4529-4f57-a9a7-387008307175',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': 'fa0e7a61-3991-459e-a957-4474aa24d269',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': 'a466664c-23b6-493f-bb4c-b676fbb7f44a',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': 'a47dba6f-1238-498b-8eab-05b19bca3c9a',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '2370dd15-3dd8-4f24-b9b1-0773d5967df7',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': '0b1a330d-1664-4a8e-9071-68daeddfa756',\n",
       "   'userData': 'gtgirl'},\n",
       "  {'persistedFaceId': '89f321f7-fc1e-4d54-9977-efd94b394773',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': 'e423ceee-3d96-4d0d-827d-db38e9f7b0e4',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '4a86311c-470f-485d-a782-c41292a64115',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': 'e8bb2a54-6916-487c-8e62-e6ccff9044ba',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '7f80fea8-687f-412a-8ada-318f54855cc1',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': 'a9ca709d-8411-4f1c-9ae0-e04cb1c39489',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '99a49936-43f9-421e-b49c-004d52b684dc',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': 'ae55f052-38bf-4d4e-ae3c-26845eb52c95',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '06baf167-b5a1-40f3-8dd1-59fab92c34a5',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '61426f38-8dd6-4219-b60e-11e7bcebd362',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': '16fa106a-4ab7-4577-9714-c952e9ab509c',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '4b5126f7-09a5-42ce-a16c-607eca8212c1',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': '456e4a22-b3a1-44d4-9e80-a2e63445b6b0',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '21a6e789-78f9-4cbb-a30d-cdc63277b10c',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '358e0f09-8283-470a-9984-89de137bab9c',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': 'df96efad-c0b9-4955-aff4-532ad8787baa',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '7c4197e5-ff9a-4021-b4df-2f8477ac7276',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'd00b348e-c1bc-4a61-be99-3cbfa64cc447',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': 'be2bbb97-8ea1-4b65-8614-008aa1291b2e',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': 'b814963c-cc88-4c4f-b5fd-0c4c5e93e4da',\n",
       "   'userData': 'gtgirl'},\n",
       "  {'persistedFaceId': '9af6131f-651a-4e14-a408-1da07d60a5f7',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '16c4b4b6-d7fb-46ee-9274-1deca29dd74f',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '86fe5625-4880-4521-b5a6-17c86617a6bc',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': 'e0d49beb-58bd-4d6d-891e-aa73e97887e5',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '58096f98-0fce-484a-b3d9-d3bff48fdb69',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': 'bd778f4e-ba68-47f5-ac84-f22042abbb9a',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '5ff86140-c503-43d0-8586-c51a47ef4972',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '311fe6d3-3f82-49e7-b23f-efc8df8cd849',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '195d6cb4-7edb-465e-a513-3635146db6b9',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': 'd719442f-fbf2-46fb-afa6-c80abbffb0ab',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'e4ab20bf-4be0-4e2a-956c-182bb7832a8b',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '97a642d5-5588-41b6-ae8c-36c7064add5f',\n",
       "   'userData': '刘宇'}],\n",
       " 'faceListId': 'renlian',\n",
       " 'name': 'ggxx',\n",
       " 'userData': 'gt'}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查你的facelist的信息\n",
    "get_facelist_url = \"https://renlian01.cognitiveservices.azure.com/face/v1.0/facelists/{}\".format(faceListId) \n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '747e4f2d-80a3-41c9-80ab-2e3182c0d5d6',\n",
       "  'faceRectangle': {'top': 527, 'left': 60, 'width': 440, 'height': 440}}]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Detect 检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://renlian01.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'https://gitee.com/forevercan/resume/raw/master/assets/images/gtboy.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': '',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "findsimilars_url = \"https://renlian01.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\"20b5c187-3563-4bea-b27a-dd1f72e7cdaa\",#取上方的faceID\n",
    "    \"faceListId\": \"gt_list\",\n",
    "#     \"faceIds\":faceId_02,\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '41eb9f2e-db12-4129-8b48-51d6b9e22690',\n",
       "  'confidence': 0.41868},\n",
       " {'persistedFaceId': '1d179489-301c-4218-aceb-e507a8f28031',\n",
       "  'confidence': 0.30263},\n",
       " {'persistedFaceId': '1f199739-99f2-4cad-b325-7f43914f58d3',\n",
       "  'confidence': 0.30263},\n",
       " {'persistedFaceId': '9a9f4c7a-3e89-413b-86ea-8f8a6c2b0830',\n",
       "  'confidence': 0.25451},\n",
       " {'persistedFaceId': '40b862d0-1200-4833-9c60-1ec1478e1e85',\n",
       "  'confidence': 0.25451},\n",
       " {'persistedFaceId': 'f56b23f3-c493-4dc9-8551-0a82ae136ca2',\n",
       "  'confidence': 0.22745},\n",
       " {'persistedFaceId': '2bd8e02b-3664-4f5e-a202-32b6aa8b5be5',\n",
       "  'confidence': 0.22745},\n",
       " {'persistedFaceId': '1c424202-5061-4f7d-8cfa-6dac6fea1665',\n",
       "  'confidence': 0.13988},\n",
       " {'persistedFaceId': 'ef7ba312-f03c-4d41-b2d4-afae62a135be',\n",
       "  'confidence': 0.13194},\n",
       " {'persistedFaceId': '6089e548-65b9-435d-98b2-d4417496ac42',\n",
       "  'confidence': 0.13194}]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>44ee1fd2-b3fe-459d-aba4-2ded992362fd</td>\n",
       "      <td>gtgirl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>204dec44-248b-4ee6-b603-1c4fd04201df</td>\n",
       "      <td>丘天惠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>55b7eb28-ead5-4d54-841a-8cff3d6c419d</td>\n",
       "      <td>林嘉茵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>89884e78-dcfa-4bb4-a7c4-bfa5941f260c</td>\n",
       "      <td>汤玲萍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>11c143b2-dda4-4d8e-a86f-ec4a8a71467c</td>\n",
       "      <td>曾雯燕</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>4f68c1e2-04c1-4533-9fce-1f0e11a27d1e</td>\n",
       "      <td>谢依希</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2e83d372-3750-4fd3-8500-6214c7be002c</td>\n",
       "      <td>杨悦聪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>9d6c53f2-952f-4950-a822-795e055c70fc</td>\n",
       "      <td>周雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>b2d7b42c-9a5f-4668-99a0-2ef5d3f39f01</td>\n",
       "      <td>刘瑜鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>71476985-0011-4b1b-811a-1e289eee7502</td>\n",
       "      <td>陈嘉仪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3a3e1b73-de5e-42b1-b27c-ae820b987b55</td>\n",
       "      <td>徐旖芊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>ec681b46-4529-4f57-a9a7-387008307175</td>\n",
       "      <td>刘心如</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>fa0e7a61-3991-459e-a957-4474aa24d269</td>\n",
       "      <td>刘宇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>a466664c-23b6-493f-bb4c-b676fbb7f44a</td>\n",
       "      <td>李婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>a47dba6f-1238-498b-8eab-05b19bca3c9a</td>\n",
       "      <td>黄智毅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2370dd15-3dd8-4f24-b9b1-0773d5967df7</td>\n",
       "      <td>黄慧文</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0b1a330d-1664-4a8e-9071-68daeddfa756</td>\n",
       "      <td>gtgirl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>89f321f7-fc1e-4d54-9977-efd94b394773</td>\n",
       "      <td>丘天惠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>e423ceee-3d96-4d0d-827d-db38e9f7b0e4</td>\n",
       "      <td>林嘉茵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>4a86311c-470f-485d-a782-c41292a64115</td>\n",
       "      <td>汤玲萍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>e8bb2a54-6916-487c-8e62-e6ccff9044ba</td>\n",
       "      <td>曾雯燕</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>7f80fea8-687f-412a-8ada-318f54855cc1</td>\n",
       "      <td>谢依希</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>a9ca709d-8411-4f1c-9ae0-e04cb1c39489</td>\n",
       "      <td>杨悦聪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>99a49936-43f9-421e-b49c-004d52b684dc</td>\n",
       "      <td>周雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>ae55f052-38bf-4d4e-ae3c-26845eb52c95</td>\n",
       "      <td>刘瑜鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>06baf167-b5a1-40f3-8dd1-59fab92c34a5</td>\n",
       "      <td>陈嘉仪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>61426f38-8dd6-4219-b60e-11e7bcebd362</td>\n",
       "      <td>徐旖芊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>16fa106a-4ab7-4577-9714-c952e9ab509c</td>\n",
       "      <td>刘心如</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>4b5126f7-09a5-42ce-a16c-607eca8212c1</td>\n",
       "      <td>刘宇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>456e4a22-b3a1-44d4-9e80-a2e63445b6b0</td>\n",
       "      <td>李婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>21a6e789-78f9-4cbb-a30d-cdc63277b10c</td>\n",
       "      <td>黄智毅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>358e0f09-8283-470a-9984-89de137bab9c</td>\n",
       "      <td>黄慧文</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>df96efad-c0b9-4955-aff4-532ad8787baa</td>\n",
       "      <td>张铭睿</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>7c4197e5-ff9a-4021-b4df-2f8477ac7276</td>\n",
       "      <td>陈婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>d00b348e-c1bc-4a61-be99-3cbfa64cc447</td>\n",
       "      <td>洪可凡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>be2bbb97-8ea1-4b65-8614-008aa1291b2e</td>\n",
       "      <td>卢继志</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>b814963c-cc88-4c4f-b5fd-0c4c5e93e4da</td>\n",
       "      <td>gtgirl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>9af6131f-651a-4e14-a408-1da07d60a5f7</td>\n",
       "      <td>丘天惠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>16c4b4b6-d7fb-46ee-9274-1deca29dd74f</td>\n",
       "      <td>林嘉茵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>86fe5625-4880-4521-b5a6-17c86617a6bc</td>\n",
       "      <td>汤玲萍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>e0d49beb-58bd-4d6d-891e-aa73e97887e5</td>\n",
       "      <td>曾雯燕</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>58096f98-0fce-484a-b3d9-d3bff48fdb69</td>\n",
       "      <td>谢依希</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>bd778f4e-ba68-47f5-ac84-f22042abbb9a</td>\n",
       "      <td>杨悦聪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>5ff86140-c503-43d0-8586-c51a47ef4972</td>\n",
       "      <td>周雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>311fe6d3-3f82-49e7-b23f-efc8df8cd849</td>\n",
       "      <td>刘瑜鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>195d6cb4-7edb-465e-a513-3635146db6b9</td>\n",
       "      <td>陈嘉仪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>d719442f-fbf2-46fb-afa6-c80abbffb0ab</td>\n",
       "      <td>徐旖芊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>e4ab20bf-4be0-4e2a-956c-182bb7832a8b</td>\n",
       "      <td>刘心如</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>97a642d5-5588-41b6-ae8c-36c7064add5f</td>\n",
       "      <td>刘宇</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId userData\n",
       "0   44ee1fd2-b3fe-459d-aba4-2ded992362fd   gtgirl\n",
       "1   204dec44-248b-4ee6-b603-1c4fd04201df      丘天惠\n",
       "2   55b7eb28-ead5-4d54-841a-8cff3d6c419d      林嘉茵\n",
       "3   89884e78-dcfa-4bb4-a7c4-bfa5941f260c      汤玲萍\n",
       "4   11c143b2-dda4-4d8e-a86f-ec4a8a71467c      曾雯燕\n",
       "5   4f68c1e2-04c1-4533-9fce-1f0e11a27d1e      谢依希\n",
       "6   2e83d372-3750-4fd3-8500-6214c7be002c      杨悦聪\n",
       "7   9d6c53f2-952f-4950-a822-795e055c70fc       周雨\n",
       "8   b2d7b42c-9a5f-4668-99a0-2ef5d3f39f01      刘瑜鹏\n",
       "9   71476985-0011-4b1b-811a-1e289eee7502      陈嘉仪\n",
       "10  3a3e1b73-de5e-42b1-b27c-ae820b987b55      徐旖芊\n",
       "11  ec681b46-4529-4f57-a9a7-387008307175      刘心如\n",
       "12  fa0e7a61-3991-459e-a957-4474aa24d269       刘宇\n",
       "13  a466664c-23b6-493f-bb4c-b676fbb7f44a       李婷\n",
       "14  a47dba6f-1238-498b-8eab-05b19bca3c9a      黄智毅\n",
       "15  2370dd15-3dd8-4f24-b9b1-0773d5967df7      黄慧文\n",
       "16  0b1a330d-1664-4a8e-9071-68daeddfa756   gtgirl\n",
       "17  89f321f7-fc1e-4d54-9977-efd94b394773      丘天惠\n",
       "18  e423ceee-3d96-4d0d-827d-db38e9f7b0e4      林嘉茵\n",
       "19  4a86311c-470f-485d-a782-c41292a64115      汤玲萍\n",
       "20  e8bb2a54-6916-487c-8e62-e6ccff9044ba      曾雯燕\n",
       "21  7f80fea8-687f-412a-8ada-318f54855cc1      谢依希\n",
       "22  a9ca709d-8411-4f1c-9ae0-e04cb1c39489      杨悦聪\n",
       "23  99a49936-43f9-421e-b49c-004d52b684dc       周雨\n",
       "24  ae55f052-38bf-4d4e-ae3c-26845eb52c95      刘瑜鹏\n",
       "25  06baf167-b5a1-40f3-8dd1-59fab92c34a5      陈嘉仪\n",
       "26  61426f38-8dd6-4219-b60e-11e7bcebd362      徐旖芊\n",
       "27  16fa106a-4ab7-4577-9714-c952e9ab509c      刘心如\n",
       "28  4b5126f7-09a5-42ce-a16c-607eca8212c1       刘宇\n",
       "29  456e4a22-b3a1-44d4-9e80-a2e63445b6b0       李婷\n",
       "30  21a6e789-78f9-4cbb-a30d-cdc63277b10c      黄智毅\n",
       "31  358e0f09-8283-470a-9984-89de137bab9c      黄慧文\n",
       "32  df96efad-c0b9-4955-aff4-532ad8787baa      张铭睿\n",
       "33  7c4197e5-ff9a-4021-b4df-2f8477ac7276       陈婷\n",
       "34  d00b348e-c1bc-4a61-be99-3cbfa64cc447      洪可凡\n",
       "35  be2bbb97-8ea1-4b65-8614-008aa1291b2e      卢继志\n",
       "36  b814963c-cc88-4c4f-b5fd-0c4c5e93e4da   gtgirl\n",
       "37  9af6131f-651a-4e14-a408-1da07d60a5f7      丘天惠\n",
       "38  16c4b4b6-d7fb-46ee-9274-1deca29dd74f      林嘉茵\n",
       "39  86fe5625-4880-4521-b5a6-17c86617a6bc      汤玲萍\n",
       "40  e0d49beb-58bd-4d6d-891e-aa73e97887e5      曾雯燕\n",
       "41  58096f98-0fce-484a-b3d9-d3bff48fdb69      谢依希\n",
       "42  bd778f4e-ba68-47f5-ac84-f22042abbb9a      杨悦聪\n",
       "43  5ff86140-c503-43d0-8586-c51a47ef4972       周雨\n",
       "44  311fe6d3-3f82-49e7-b23f-efc8df8cd849      刘瑜鹏\n",
       "45  195d6cb4-7edb-465e-a513-3635146db6b9      陈嘉仪\n",
       "46  d719442f-fbf2-46fb-afa6-c80abbffb0ab      徐旖芊\n",
       "47  e4ab20bf-4be0-4e2a-956c-182bb7832a8b      刘心如\n",
       "48  97a642d5-5588-41b6-ae8c-36c7064add5f       刘宇"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "#facelist里面的数据\n",
    "adf = pd.json_normalize(r_get_facelist.json()['persistedFaces'])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>41eb9f2e-db12-4129-8b48-51d6b9e22690</td>\n",
       "      <td>0.41868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1d179489-301c-4218-aceb-e507a8f28031</td>\n",
       "      <td>0.30263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1f199739-99f2-4cad-b325-7f43914f58d3</td>\n",
       "      <td>0.30263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9a9f4c7a-3e89-413b-86ea-8f8a6c2b0830</td>\n",
       "      <td>0.25451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>40b862d0-1200-4833-9c60-1ec1478e1e85</td>\n",
       "      <td>0.25451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>f56b23f3-c493-4dc9-8551-0a82ae136ca2</td>\n",
       "      <td>0.22745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2bd8e02b-3664-4f5e-a202-32b6aa8b5be5</td>\n",
       "      <td>0.22745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1c424202-5061-4f7d-8cfa-6dac6fea1665</td>\n",
       "      <td>0.13988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>ef7ba312-f03c-4d41-b2d4-afae62a135be</td>\n",
       "      <td>0.13194</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>6089e548-65b9-435d-98b2-d4417496ac42</td>\n",
       "      <td>0.13194</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  41eb9f2e-db12-4129-8b48-51d6b9e22690     0.41868\n",
       "1  1d179489-301c-4218-aceb-e507a8f28031     0.30263\n",
       "2  1f199739-99f2-4cad-b325-7f43914f58d3     0.30263\n",
       "3  9a9f4c7a-3e89-413b-86ea-8f8a6c2b0830     0.25451\n",
       "4  40b862d0-1200-4833-9c60-1ec1478e1e85     0.25451\n",
       "5  f56b23f3-c493-4dc9-8551-0a82ae136ca2     0.22745\n",
       "6  2bd8e02b-3664-4f5e-a202-32b6aa8b5be5     0.22745\n",
       "7  1c424202-5061-4f7d-8cfa-6dac6fea1665     0.13988\n",
       "8  ef7ba312-f03c-4d41-b2d4-afae62a135be     0.13194\n",
       "9  6089e548-65b9-435d-98b2-d4417496ac42     0.13194"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度的数据\n",
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [persistedFaceId, userData, confidence]\n",
       "Index: []"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(adf,bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
